"""
Test Frame Requirements:

Sign In Page:
	"Sign In" window title
	Welcome Message
	Username label -> allows user text input
	Username entry
	Password label
	Password entry -> allows user text input
	Remember me radio button -> toggle on/off just for show
	Sign in button -> students go to Student Courses View, teachers go to Teacher Course View, proctors go to Proctor Student List View
		Sign in button is currently tripled for convenience to testing.

Proctor Student List View:
	"Student List" window title
	Proctor button list (Home, Search, current window)
	4 student identity frames (that act as buttons?) -> Proctor Student View
	broadcast chat box
	
Proctor Student View:
	"Student View" window title
	Proctor button list (Home, Search, current window)
	student name label
	test name label
	test info button -> Test Info View
	Time/Event table
	chat box
	picture of student
	confidence level canvas?
	note taking entry box
	add note button

Test Info View:
	"Test Info View" window title
	Proctor button list (Home, Search, current window)
	text box with info about the test

Teacher Course View:
	"Course List" window title
	Teacher button list (Home, Search, current window, Proctor Mode, Switch to Student List, Test Info)
	two courses as frames:
		Course name label
		Test/Number of Questions/Percent Completed/Average Mark table with scrollbar
	View Course button -> Teacher? Course View
	View Student List button -> Teacher Course Student List
	move up button
	move down button
	add new course button

Teacher Test View:
	"Course View" window title
	Teacher button list
	two midterms as frames:
		Midterm name label
		Section/Number of Questions/Percent Completed/Average Mark table with scrollbar
	View button -> Teacher TestInfo View?
	move up button
	move down button
	add new test button

Teacher TestEdit View:
	"Test View" window title
	teacher button list
	listbox for sections with questions in them with scrollbar
	Frames for test sections:
		midterm section label
		questions inside editable text boxes
		edit button inside frame
		up button inside frame
		down button inside frame
		View button outside frame
		move up button outisde frame
		move down button outisde frame
	add section button

Teacher Course Student List:
	"Student List" window title
	teacher button list
	listbox for student names
	frames for each student:
		student name label
		student number label
		student picture
		#incidents and course mark labels
		view details button
	add student to class button
	proctor list label
	list of proctor names
	add proctor button

Teacher Student View:
	"Student" window title
	teacher button list
	labels for student name, # incidents, student number, current grade
	picture of student
	frames for test sections:
		section name label
		date of completion label
		proctor view button
		mark button
		image of confidence sensor
	
Teacher TestInfo View:
	"Test Info" window title
	teacher button list
	editable text box for teacher to write test info

System Admin Students:
	"Test Info" window title
	sysadmin button list (Home, Search, window name, Switch to Proctor)
	course listbox
	new course button
	enlisted student listbox
	add button
	remove button
	student search box
	new student button

System Admin Proctors:
	"Test Info" window title
	sysadmin button list (Home, Search, window name, Switch to Students)
	course listbox
	new course button
	enlisted proctor listbox
	add button
	remove button
	proctor search box
	new proctor button

Student Courses View:
	"Course List" window title
	student button list (Home, Search, window name)
	two courses as frames:
		Course name label
		Test/Number of Questions/Test Due Date/Test Written Date/Mark table with scrollbar
	View Course button -> Student test view

Student Test View:
	"Course View" window title
	student button list
	two midterms as frames:
		Midterm name label
		Section/Number of Questions/Section Written Date/Mark table with scrollbar
	View Marks button -> Student Mark View
	Start Test button -> Student Test Taking View
	
Student Test Taking View:
	"Course View" window title
	student button list
	list of questions as listbox with scrollbar
	frames for questions in them:
		label with question name/description and radio buttons for choices
		label with question name/picture of a graph and a slider bar under it
	proctor chat box

Student Mark View:
	"Marks View" window title
	student button list
	list of questions as listbox with scrollbar
	frames for questions in them:
		label with question name/description and radio buttons for choices with a correct/incorrect choice highlighted and mark given
		label with question name/picture of a graph and a slider bar under it with a correct/incorrect choice highlighted and mark given
	proctor chat box
	
"""

import sys
import Tkinter as tk

root = tk.Tk()

currentFrame = None

def switch_frame(frame_creation_fn):
	global currentFrame

	if currentFrame:
		currentFrame.destroy()

	currentFrame = frame_creation_fn()
	
def send_broadcast_msg(strvar, broadcast_out):
	if not strvar.get():
		return

	broadcast_out['state'] = 'normal'
	broadcast_out.insert(tk.END, '\n' + strvar.get())
	broadcast_out.see(tk.END)
	broadcast_out['state'] = 'disabled'
	strvar.set('')

def create_send_broadcast_command(strvar, broadcast_out):
	return lambda:send_broadcast_msg(strvar, broadcast_out)

def create_broadcast_frame(parent, initial_broadcast, initial_msg):
	broadcastFrame = tk.Frame(parent)

	broadcastChatBox = tk.Text(broadcastFrame, height=3)
	broadcastChatBox.insert(tk.INSERT, initial_broadcast)
	broadcastChatBox['state'] = 'disabled'
	broadcastChatBox.pack()

	broadcastMsg = tk.StringVar()
	broadcastEntryBox = tk.Entry(broadcastFrame, text=initial_msg, textvariable=broadcastMsg)
	broadcastEntryBox.pack()

	broadcastSubmitButton = tk.Button(broadcastFrame, text = "Submit", command=create_send_broadcast_command(broadcastMsg, broadcastChatBox)).pack()

	return broadcastFrame

def create_student_top_buttons_frame(parent):
	buttonFrame = tk.Frame(parent)
	homeButton = tk.Button(buttonFrame, text="Home").pack()
	searchButton = tk.Button(buttonFrame, text="Search").pack()
	return buttonFrame

def create_sign_in():
	root.title("Sign in")
	signInFrame = tk.Frame(root)

	userNameLabel = tk.Label(signInFrame, text="Username").pack()
	userNameText = tk.Text(signInFrame, height=1).pack()

	passwordLabel = tk.Label(signInFrame, text="Password").pack()
	passwordText = tk.Text(signInFrame, height=1).pack()

	studentSignInButton = tk.Button(signInFrame, text="Sign in (Student)", command=switch_to_student_course_view).pack()
	teacherSignInButton = tk.Button(signInFrame, text="Sign in (Teacher)", command=switch_to_teacher_course_view).pack()
	proctorSignInButton = tk.Button(signInFrame, text="Sign in (Proctor)", command=switch_to_proctor_student_list_view).pack()

	signInFrame.pack()

	return signInFrame

def switch_to_student_course_view():
	switch_frame(create_student_course_view)

def create_student_course_view():
	root.title("Course View")
	courseViewFrame = tk.Frame(root)
	
	buttonHeader = create_student_top_buttons_frame(courseViewFrame)
	buttonHeader.pack()

	course1Label = tk.Label(courseViewFrame, text="Course 1").pack()
	course1View = tk.Button(courseViewFrame, text="View Course", command=switch_to_student_test_view).pack()

	course2Label = tk.Label(courseViewFrame, text="Course 2").pack()
	course2View = tk.Button(courseViewFrame, text="View Course", command=switch_to_student_test_view).pack()

	courseViewFrame.pack()

	return courseViewFrame

def switch_to_student_test_view():
	switch_frame(create_student_test_view)

def create_student_test_view():
	root.title("Test View")
	testViewFrame = tk.Frame(root)

	buttonHeader = create_student_top_buttons_frame(testViewFrame)
	buttonHeader.pack()

	midterm1Label = tk.Label(testViewFrame, text="Midterm 1").pack()
	midterm1DetailedMarks = tk.Button(testViewFrame, text="View Marks", command=switch_to_student_mark_view).pack()
	
	midterm2Label = tk.Label(testViewFrame, text="Midterm 2").pack()
	midterm2DetailedMarks = tk.Button(testViewFrame, text="Detailed Marks", command=switch_to_student_mark_view).pack()
	midterm2StartSection = tk.Button(testViewFrame, text="Start Next Section", command=switch_to_student_test_taking_view).pack()

	midterm3Label = tk.Label(testViewFrame, text="Midterm 3").pack()
	midterm3StartTest = tk.Button(testViewFrame, text="Start Test", command=switch_to_student_test_taking_view).pack()

	testViewFrame.pack()

	return testViewFrame

def switch_to_student_test_taking_view():
	switch_frame(create_student_test_taking_view)

def create_student_test_taking_view():
	root.title("Test Taking View")
	testTakingFrame = tk.Frame(root)

	buttonHeader = create_student_top_buttons_frame(testTakingFrame)
	buttonHeader.pack()

	questionListBox = tk.Listbox(testTakingFrame)
	questionListBox.insert(tk.END, "1: Question 1", "2: Question 2", "3: Question 3", "4: Question 4")
	questionListBox.pack()

	exampleQuestion1Frame = tk.Frame(testTakingFrame, relief=tk.RIDGE, borderwidth=5)
	exampleQuestion1Descr = tk.Label(exampleQuestion1Frame, text="How much wood would a woodchuck chuck if a woodchuck could chuck wood?").pack()
	exampleQuestion1Ans = tk.IntVar()
	exampleQuestion1Choice1 = tk.Radiobutton(exampleQuestion1Frame, text="1", variable=exampleQuestion1Ans, value=1).pack()
	exampleQuestion1Choice2 = tk.Radiobutton(exampleQuestion1Frame, text="2", variable=exampleQuestion1Ans, value=2).pack()
	exampleQuestion1Choice3 = tk.Radiobutton(exampleQuestion1Frame, text="3", variable=exampleQuestion1Ans, value=3).pack()
	exampleQuestion1Choice4 = tk.Radiobutton(exampleQuestion1Frame, text="Not Applicable", variable=exampleQuestion1Ans, value=4).pack()
	exampleQuestion1Frame.pack()

	proctorChatBox = create_broadcast_frame(testTakingFrame, "<Broadcast> 3:34pm: Test ends in 10 minutes. Good luck!", "Type to chat with proctor").pack()

	testTakingFrame.pack()

	return testTakingFrame

def switch_to_student_mark_view():
	switch_frame(create_student_mark_view)

def create_student_mark_view():
	root.title("Mark View")
	markViewFrame = tk.Frame(root)

	buttonHeader = create_student_top_buttons_frame(markViewFrame)
	buttonHeader.pack()

	questionListBox = tk.Listbox(markViewFrame)
	questionListBox.insert(tk.END, "1: Question 1", "2: Question 2", "3: Question 3", "4: Question 4")
	questionListBox.pack()

	exampleQuestion1Frame = tk.Frame(markViewFrame, relief=tk.RIDGE, borderwidth=5)
	exampleQuestion1Descr = tk.Label(markViewFrame, text="How much wood would a woodchuck chuck if a woodchuck could chuck wood?").pack()
	exampleQuestion1Ans = tk.IntVar()
	exampleQuestion1Choice1 = tk.Radiobutton(markViewFrame, text="1", state=tk.DISABLED).pack()
	exampleQuestion1Choice2 = tk.Radiobutton(markViewFrame, text="2", bg='#000000', state=tk.DISABLED).pack()
	exampleQuestion1Choice3 = tk.Radiobutton(markViewFrame, text="3", bg='#ff0000', state=tk.DISABLED).pack()
	exampleQuestion1Choice4 = tk.Radiobutton(markViewFrame, text="Not Applicable", state=tk.DISABLED).pack()
	exampleQuestion1Mark = tk.Label(markViewFrame, text="0/1", fg='#ff0000').pack()
	exampleQuestion1Frame.pack()

	proctorChatBox = create_broadcast_frame(markViewFrame, "<Broadcast> 3:34pm: Test ends in 10 minutes. Good luck!", "Type to chat with proctor").pack()

	markViewFrame.pack()

	return markViewFrame

def switch_to_teacher_course_view():
	switch_frame(create_teacher_course_view)

def create_teacher_course_view():
	root.title("Course View")
	courseViewFrame = tk.Frame(root)
	
	course1Label = tk.Label(courseViewFrame, text="Course 1").pack()
	course1View = tk.Button(courseViewFrame, text="View Course", command=switch_to_teacher_test_view).pack()
	viewStudentList1 = tk.Button(courseViewFrame, text="View Student List", command=switch_to_teacher_test_view).pack()
	moveUp1 = tk.Button(courseViewFrame, text="Move Up", command=switch_to_teacher_test_view).pack()
	moveDown1 = tk.Button(courseViewFrame, text="Move Down", command=switch_to_teacher_test_view).pack()

	course2Label = tk.Label(courseViewFrame, text="Course 2").pack()
	course2View = tk.Button(courseViewFrame, text="View Course", command=switch_to_teacher_test_view).pack()
	viewStudentList2 = tk.Button(courseViewFrame, text="View Student List", command=switch_to_teacher_test_view).pack()
	moveUp2 = tk.Button(courseViewFrame, text="Move Up", command=switch_to_teacher_test_view).pack()
	moveDown2 = tk.Button(courseViewFrame, text="Move Down", command=switch_to_teacher_test_view).pack()

	courseViewFrame.pack()

def switch_to_teacher_test_view():
	switch_frame(create_teacher_test_view)

def create_teacher_test_view():
	root.title("Test View")
	testViewFrame = tk.Frame(root)

	midterm1Label = tk.Label(testViewFrame, text="Midterm 1").pack()
	midterm1DetailedMarks = tk.Button(testViewFrame, text="View").pack()
	midterm1MoveUp = tk.Button(testViewFrame, text="Move Up").pack()
	midterm1MoveDown = tk.Button(testViewFrame, text="Move Down").pack()
	
	midterm2Label = tk.Label(testViewFrame, text="Midterm 2").pack()
	midterm2DetailedMarks = tk.Button(testViewFrame, text="View").pack()
	midterm2MoveUp = tk.Button(testViewFrame, text="Move Up").pack()
	midterm2MoveDown = tk.Button(testViewFrame, text="Move Down").pack()

	createNewTest = tk.Button(testViewFrame, text="Create New Test").pack()

	testViewFrame.pack()

	return testViewFrame

def switch_to_proctor_student_list_view():
	switch_frame(create_proctor_student_list_view)

def create_proctor_student_list_view():
	root.title("Student List View")
	studentListFrame = tk.Frame(root)

	JohnLabel = tk.Label(studentListFrame, text="John Smith").pack()
	BettyLabel = tk.Label(studentListFrame, text="Betty Williams").pack()
	StudentLabel = tk.Label(studentListFrame, text="Student Name").pack()
	SmartyMcSmartyLabel = tk.Label(studentListFrame, text="Smarty McSmarty").pack()

	broadcastBox = create_broadcast_frame(studentListFrame, "Welcome, Proctor.", "Enter broadcast here").pack()

	studentListFrame.pack()

	return studentListFrame

def main():
	switch_frame(create_sign_in)

	root.mainloop()

if __name__ == '__main__':
	main()
	sys.exit()
